package cn.com.demo.shiro.service.impl;

import cn.com.demo.shiro.dao.TShiroResPermissionDao;
import cn.com.demo.shiro.dao.TShiroUserDao;
import cn.com.demo.shiro.dao.TShiroUserPermissionDao;
import cn.com.demo.shiro.entity.TShiroResPermission;
import cn.com.demo.shiro.entity.TShiroUser;
import cn.com.demo.shiro.entity.TShiroUserPermission;
import cn.com.demo.shiro.service.UserService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private TShiroUserDao tShiroUserDao;
    @Autowired
    private TShiroUserPermissionDao userPermissionDao;
    @Autowired
    private TShiroResPermissionDao tShiroResPermissionDao;
    @Override
    public TShiroUser getUserByUserName(String userName) {
        QueryWrapper<TShiroUser> query = new QueryWrapper<>();
        query.eq("username",userName);
        return tShiroUserDao.selectOne(query);
    }

    @Override
    public Set<String> getUserPermission(Integer userId) {
        return userPermissionDao.selectPermission(userId);
    }

    @Override
    public List<TShiroResPermission> getResPermission() {
        return tShiroResPermissionDao.selectByMap(new HashMap<>());
    }
}
